﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using DotNetNuke.Common.Utilities;
using Ivevane.Modules.Newslider.Data;

namespace Ivevane.Modules.Newslider.Components
{
    public class ArcticleController
    {
        public static Article GetArticle(int itemId, int moduleId)
        {
            return CBO.FillObject<Article>(DataProvider.Instance().GetArticle(itemId, moduleId));
        }

        public static List<Article> GetCurrentArticles(int moduleId, DateTime startDate)
        {
            return CBO.FillCollection<Article>(DataProvider.Instance().GetCurrentArticles(moduleId, startDate));
        }

        public static List<Article> GetAllArticles(int moduleId, DateTime startDate, DateTime endDate)
        {
            return CBO.FillCollection<Article>(DataProvider.Instance().GetAllArticles(moduleId, startDate, endDate));
        }

        public static List<Article> GetExpiredArtciles(int moduleId)
        {
            return CBO.FillCollection<Article>(DataProvider.Instance().GetExpiredArticles(moduleId));
        }

        public static void DeleteArticle(int moduleId, int itemId)
        {
            DataProvider.Instance().DeleteArticle(moduleId, itemId);
        }

        public static int SaveArticle(Article a, int tabId)
        {
            if (a.ItemId < 1)
            {
                a.ItemId = DataProvider.Instance().AddArticle(a);

                // content item integration
            }
            else
            {
                DataProvider.Instance().UpdateArticle(a);
            }

            return a.ItemId;
        }
    }
}